<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Comet echo RPC</title>

		<script type="text/javascript">
			var djConfig = { isDebug: false };
		</script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/dojo/dojo.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/behaviour.js"></script>
		<script language="JavaScript" type="text/javascript">

	function $() {
	  return document.getElementById(arguments[0]);
	}


        var EvUtil =
        {
          getKeyCode : function(ev)
          {
            var keyc;
            if (window.event)
              keyc=window.event.keyCode;
            else
              keyc=ev.keyCode;
            return keyc;
          }
        };

        var echoBehaviours = 
        { 
            '#phrase' : function(element)
            {
              element.setAttribute("autocomplete","OFF");
              element.onkeyup = function(ev)
              {   
                  var keyc=EvUtil.getKeyCode(ev);
                  if (keyc==13 || keyc==10)
                  {
                    echoRpc($('phrase').value);
                    $('phrase').value='';
	                return false;
	              }
                  return true;
              }
            },
  
            '#sendB' : function(element)
            {
              element.onclick = function(event)
              {
                echoRpc($('phrase').value);
                $('phrase').value='';
                return false;
              }
            }
          };

			function setUp()
			{
				dojo.require("dojo.io.cometd");
				dojo.require("dojo.event.*");

				dojo.event.connect(cometd, "finishInit", 
					function(type, data, evt, request){
						cometd.subscribe(
							"/rpc/echo/"+cometd.clientId,
							true, 
							"echoRpcReturn"
						);
					}
				);

                cometd.init({}, "${pageContext.request.contextPath}/cometd");

				Behaviour.register(echoBehaviours);
			}

			function echoRpc(msg)
			{
       		    cometd.publish("/rpc/echo", msg);
			}
			
			function echoRpcReturn(msg)
			{
                $("responses").innerHTML+=msg.timestamp+" "+msg.channel+": "+msg.data + "<br/>";
			}

			dojo.addOnLoad(setUp());
		</script>
	</head>
	<body>
	
	<h1>Echo Test (Spring Enabled)</h1>

    <div>Echo:&nbsp;<input id="phrase" type="text"></input> <input id="sendB" class="button" type="submit" name="join" value="Send"/>
    </div>
    <pre id="responses"></pre>    

    <h3>Java Code</h3>

    <pre>
        ...
    </pre>

    <h3>Spring Configuration</h3>

    <pre>
        ...
    </pre>

	</body>
</html>
